# $Id$
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>

pkgbase=kdemultimedia-kmix
pkgname=('kdemultimedia-kmix' 'kmix')
pkgver=17.08.1
pkgrel=1
pkgdesc="KDE volume control program"
url='https://kde.org/applications/multimedia/kmix/'
arch=('i686' 'x86_64')
license=('GPL' 'LGPL' 'FDL')
makedepends=('cmake' 'automoc4' 'kdelibs' 'extra-cmake-modules' 'python' 'kdoctools' 'kdelibs4support' 'plasma-framework'
             'libcanberra' 'kdesignerplugin')
source=("https://download.kde.org/stable/applications/${pkgver}/src/kmix-${pkgver}.tar.xz"{,.sig}
        'use-qdbus-qt4.patch')
sha256sums=('e531e0bce620948cc77c3f372163aba53804f7fb64d7e1992852bf9fc81de8f0'
            'SKIP'
            '8f9de41863c0aa48ec08f3b8a3824bf410c253da7cdc9e3198ec3fc1bea45c99')
validpgpkeys=(CA262C6C83DE4D2FB28A332A3A6A4DB839EAA6D7  # Albert Astals Cid <aacid@kde.org>
              F23275E4BF10AFC1DF6914A6DBD2CE893E2D1C87) # Christoph Feck <cfeck@kde.org>

prepare() {
  mkdir -p build{,-kf5}

  cp -r kmix-$pkgver kmix-kf5-$pkgver

  # FS#40786
  cd kmix-${pkgver}
  sed -i 's|qdbus|qdbus-qt4|' apps/kmixremote
  
  # https://bugs.kde.org/show_bug.cgi?id=343621
  cd ../kmix-kf5-$pkgver
  sed -e 's|${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}|${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake/modules|' -i CMakeLists.txt
}

build() {
  cd build
  cmake ../kmix-${pkgver} \
    -DCMAKE_BUILD_TYPE=Release \
    -DKDE4_BUILD_TESTS=OFF \
    -DCMAKE_INSTALL_PREFIX=/usr
  make

  cd ../build-kf5
  cmake ../kmix-kf5-${pkgver} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    -DKMIX_KF5_BUILD=ON \
    -DKDE_INSTALL_LIBDIR=lib
  make
}

package_kdemultimedia-kmix() {
  depends=('kdebase-runtime')
  optdepends=('libcanberra-pulse: PulseAudio support')
  groups=('kde-applications' 'kdemultimedia')
  
  cd build
  make DESTDIR="$pkgdir" install
}

package_kmix() {
  pkgdesc="KDE volume control program (experimental KF5 version)"
  depends=('kdelibs4support' 'libcanberra' 'hicolor-icon-theme')
  optdepends=('libcanberra-pulse: PulseAudio support')
  conflicts=('kdemultimedia-kmix')
  
  cd build-kf5
  make DESTDIR="$pkgdir" install
}
